<?php
/*
* @Created by Phpstorm
* @User: Zhangxinlei
* @Date: 
* @Time:
* @content:用户管理（zero_admin_passport）
*/
declare (strict_types = 1);
namespace app\common\model;

use think\facade\Db;
use think\facade\Request;
use think\facade\Session;
use think\Model;
use think\model\concern\SoftDelete;
class AdminPassport extends Model
{
    public static function getList()
    {
        $req = Request::instance()->param();
        $where = [];
        // 时间搜索
        if(isset($req['create_time']) and !empty($req['create_time'])) {
            
            $min_time = strtotime($req['create_time']);
            $max_time = $min_time + 24 * 60 * 60;
            $where[] = ['create_time','between',[$min_time, $max_time]];
        }
        //用户信息
        if (isset($req['keywords']) and !empty($req['keywords'])) {
            $where[] = ['realname|id|name|tel|openid', 'like', "%" . $req['keywords'] . "%"];
        }
        //会员状态
        if (isset($req['type']) and !empty($req['type'])) {
            $where[] =  ['type', '=',$req['type']];
        }
        $list = self::with(['defaultBranch'])
            ->field('id,name,avatar,openid,type,realname,tel,inviter,staff_id,filiale,cashback,balance,create_time,group_id')
            ->where($where)
            ->order('create_time desc')
            ->paginate($req['limit'])->each(function($v,$k){
                $staff = self::field('realname,id')->where('id',$v['staff_id'])->find();
                $inviter = self::field('name,id')->where('id',$v['inviter'])->find();
                $v['staffrealname'] = $staff['realname'];
                $v['invitername'] = $inviter['name'];
                return $v;
            });
        return ['code'=>0,'data'=>$list->items(),'extend'=>['count' => $list->total(), 'limit' => $req['limit']]];
    }
    /**
     * Undocumented function
     * 分公司
     * @return void
     */
    public function defaultBranch(){
        return $this->hasOne('AdminBranch','id','filiale','','left')->bind([
                'branchname'  => 'name',
                'bid'  => 'id',
        ]);
    }


    
    

}